<?php

class elemform {
    
    static private $obj    = '';
    
    static function select($id,$nom,$value = '') {
        
        self::setObjDB($id);
        
        $html  = '<select id="'.$id.'" name="'.$id.'">';
        $html .= '<option value="0">Nenhum</option>';
        $row = self::$obj->fetchAll()->toArray();
        foreach($row as $r){ 
            $selected = ($r[$id] == $value) ? 'selected=""':'';
            $html .= '<option value="'.$r[$id].'" '.$selected.'>'.$r[$nom].'</option>';
        }
        $html .= '</select>';
        
        return $html;
    }
    static function selectPdr($id,$nom,$value = '',$key = '') {
        $html  = '<select id="'.$id.'" name="'.$id.'">';
        
        if($key > ''){
            self::setObjDB($id,$key);
            
        }else{
            $html .= '<option value="0">Nenhum</option>';
        }
        $html .= '</select>';
        return $html;
        
    } 
    
    static function checkbox($id,$setValue, $value) {
        $checked = ($setValue == $value) ? 'checked=""':'';
        $hmlt = '<input type="checkbox" '.$checked.' name="'.$id.'" value="'.$setValue.'" />';
        return $hmlt;
    }
    
    static function radio($id,$class ='',$setValue, $value) {
        $checked = ($setValue == $value) ? 'checked=""':'';
        if($class != '') $class = 'class="'.$class.'"';
        $hmlt = '<input type="radio" '.$checked.' name="'.$id.'" '.$class.' value="'.$setValue.'" />';
        return $hmlt;
    }
    
    static function setObjDB($db = '',$key = '') {
        
        //$where = ($key > '') ? 'CTS_ID = '.$key:$db.' > 0';
        
        switch($db) {
            //case $db == 'CTS_ID': self::$obj = new Sistema_Model_DbTable_Catsegmento(); break;
            //case $db == 'CAT_ID': self::$obj = new Sistema_Model_DbTable_Categoria(); break;
            //case $db == 'MAT_ID': self::$obj = new Sistema_Model_DbTable_Material(); break;
            //case $db == 'GRA_ID': self::$obj = new Sistema_Model_DbTable_Gradetamanhos(); break;
            //case $db == 'GRC_ID': self::$obj = new Sistema_Model_DbTable_Gradecor(); break;
            //case $db == 'FOR_ID': self::$obj = new Sistema_Model_DbTable_Fornecedor(); break;
        } 
    }
    
    static function selectArray($id,$nom,$arr,$value = '') {
        
        self::setObjDB($id);
        
        $html  = '<select id="'.$id.'" name="'.$id.'">';
        $html .= '<option value="0">Nenhum</option>';
        foreach($arr as $key => $r){ 
            $selected = ($key == $value) ? 'selected=""':'';
            $html .= '<option value="'.$key.'" '.$selected.'>'.$r.'</option>';
        }
        $html .= '</select>';
        
        return $html;
    }
    
}